Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement TaskModuleWithDocumentConverter #114

Merged
merged 9 commits into from
Sep 18, 2024

Conversation

ArneBinder
Copy link
Owner

@ArneBinder ArneBinder commented Sep 17, 2024

This implements the abstract class TaskModuleWithDocumentConverter. It allows to easily create "wrapped" taskmodules which have the same core functionality as the base taskmodule, but require to have some document conversion before the encoding / after prediction attachments.

It requires to implement the following methods:

@abstractmethod
def _convert_document(self, document: DocumentType) -> ConvertedDocumentType:
    """Convert a document of the taskmodule document type to the 
    expected document type of the wrapped taskmodule.

    Args:
        document: the input document

    Returns: the converted document
    """
    pass

@abstractmethod
def _integrate_predictions_from_converted_document(
    self,
    document: DocumentType,
    converted_document: ConvertedDocumentType,
) -> TextDocumentWithLabeledSpansAndBinaryRelations:
    """Convert the predictions at the respective layers of the converted_document and add them
    to the original document predictions.

    Args:
        document: document to attach the converted predictions to
        converted_document: the document returned by the wrapped taskmodule, including predictions
    """
    pass

Also, if the wrapped taskmodule .document_type returns a document type, it is required to implement:

@property
def document_type(self) -> Optional[Type[Document]]:
    pass

@codecov-commenter
Copy link

codecov-commenter commented Sep 17, 2024

Codecov Report

Attention: Patch coverage is 91.48936% with 4 lines in your changes missing coverage. Please review.

Project coverage is 95.75%. Comparing base (cccdd33) to head (ba5c80a).

Files with missing lines Patch % Lines
...dules/common/taskmodule_with_document_converter.py 91.30% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #114      +/-   ##
==========================================
+ Coverage   95.71%   95.75%   +0.04%     
==========================================
  Files          60       61       +1     
  Lines        4990     5037      +47     
==========================================
+ Hits         4776     4823      +47     
  Misses        214      214              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ArneBinder ArneBinder merged commit 6e198c2 into main Sep 18, 2024
2 checks passed
@ArneBinder ArneBinder deleted the taskmodules/TaskModuleWithDocumentConverter branch September 18, 2024 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants